package com.cjm.one.custom.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cjm.one.custom.service.CustomAddressService;
import com.cjm.one.custom.mapper.CustomAddressMapper;
import com.cjm.one.model.custom.entity.CustomAddress;

import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

/**
* @author 29289
* @description 针对表【custom_address(用户地址表)】的数据库操作Service实现
* @createDate 2024-09-05 16:25:23
*/
@Service
public class CustomAddressServiceImpl extends ServiceImpl<CustomAddressMapper, CustomAddress>
    implements CustomAddressService {
    @Resource
    private CustomAddressMapper customAddressMapper;

    @Override
    public Page<CustomAddress> pageList(Integer current, Integer size, Long id) {

        Page<CustomAddress> page = new Page<>(current, size);
        LambdaQueryWrapper<CustomAddress> customAddressLambdaQueryWrapper = new LambdaQueryWrapper<>();
        customAddressLambdaQueryWrapper.eq(CustomAddress::getCustomId, id);
        Page<CustomAddress> customAddressPage = customAddressMapper.selectPage(page, customAddressLambdaQueryWrapper);
        return customAddressPage;
    }

    @Override
    public Boolean add(CustomAddress customAddress) {

        return customAddressMapper.insert(customAddress) > 0;
    }

    @Override
    public Boolean deleteByIdAndCustomId(Long id, Long customId) {
        LambdaQueryWrapper<CustomAddress> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(CustomAddress::getId, id).eq(CustomAddress::getCustomId, customId);
        return remove(queryWrapper);
    }

    @Override
    public CustomAddress getAddressInfo(Long id, Long customId) {
        LambdaQueryWrapper<CustomAddress> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(CustomAddress::getId, id).eq(CustomAddress::getCustomId, customId);
        CustomAddress customAddress = customAddressMapper.selectOne(queryWrapper);
        return customAddress;
    }

    @Override
    public CustomAddress getDefaultById(Long customId) {

        LambdaQueryWrapper<CustomAddress> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(CustomAddress::getCustomId, customId).eq(CustomAddress::getIsDefault, 1);
        CustomAddress customAddress = customAddressMapper.selectOne(queryWrapper);
        return customAddress;
    }
}




